function Sproing( r, t ) {
  var self = this;
  
  this.x = 0;
  this.y = 0;
  this.r = r;
  this.t = t;
  this.child = 0;
  this.parent = 0;

  this.translate = function() {
    this.corner.setAttribute( "transform", "translate("+(this.x+this.r)+","+(this.y+this.r)+")" );
  };

  this.rotate = function( dt ) {
    this.t += dt;
    this.center.setAttribute( "transform", "rotate("+this.t+")" );
  };

  this.addChild = function( cs ){
    this.child = cs;
    this.center.appendChild( this.child.corner );
    this.child.parent = self;
    cs.moveTo( this.r, -this.r );
  };

  this.tick = function() {
    var sproing = self;
    while( sproing != 0 ) {
      sproing.rotate( 10 );
      sproing = sproing.child; 
   }
  };

  this.moveTo = function(x,y) {
    this.x = x;
    this.y = y;
    this.translate();
  };

  this.corner = document.createElementNS("http://www.w3.org/2000/svg", "g");
  this.center = document.createElementNS("http://www.w3.org/2000/svg", "g");
  this.corner.appendChild( this.center );
  this.translate();
  this.circle = document.createElementNS("http://www.w3.org/2000/svg", "circle");
  this.center.appendChild( this.circle );
  this.line = document.createElementNS("http://www.w3.org/2000/svg", "line");
  this.center.appendChild( this.line );

  this.circle.setAttribute( "cx", "0" );
  this.circle.setAttribute( "cy", "0" );
  this.circle.setAttribute( "r", r );
  this.line.setAttribute( "x1", "0" );
  this.line.setAttribute( "y1", "0" );
  this.line.setAttribute( "x2", r );
  this.line.setAttribute( "y2", "0" );
  this.center.setAttribute( "stroke", "white" );
  this.center.setAttribute( "fill", "black" );
  this.center.setAttribute( "onclick", "tick()" );
  this.center.setAttribute( "transform", "rotate("+t+")" );

}
